<?php

namespace app\api2\controller;


use \app\common\controller\Api;
use \think\Db;


class Statistics extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $needWorkerLogin = ['money'];


    public function money()
    {
        if ($this->request->isPost()) {

            $data = (array)$this->_data;

            //即将到账
            $arrive = Db::table('fa_order')
                ->where('status', 1)
                ->where('worker_id', $data['user_id'])
                ->whereOr('worker_id', 'like', ' %,' . $data['user_id'])
                ->whereOr('worker_id', 'like', $data['user_id'] . ',%')
                ->whereOr('worker_id', 'like', '%,' . $data['user_id'] . ',%')
                ->sum('pay_price');
            //累计到账
            $toAccountSum = Db::table('fa_worker_money_log')
                ->where('worker_id', $data['user_id'])
                ->sum('money');
            //累计结算
            $clearingSum = Db::table('fa_clearing_log')
                ->where('worker_id', $data['user_id'])
                ->sum('money');

            //可结算余额
            $balance = Db::table('fa_worker_bank')
                ->where('worker_id', $data['user_id'])
                ->value('balance');

            $this->success('ok', ['arrive' => $arrive, 'ToAccountSum' => $toAccountSum, 'clearingSum' => $clearingSum, 'balance' => $balance], 200);
        }
    }
}